package com.ido.otaclient.main;

import android.text.TextUtils;
import android.util.Log;

import com.ido.otaclient.base.ApiConstant;
import com.ido.otaclient.base.IDLog;
import com.ido.otaclient.env.AppEnv;
import com.ido.otaclient.util.ToastUtils;
import com.ido.otaclient.util.WifiUtils;

/**
 * Copyright (c) 2019 深圳市爱都科技有限公司. All rights reserved.
 *
 * @Author: xyb
 * @CreateDate: 2020-02-25 10:07
 * @description
 */
public class MainPersenter implements MainContract.Presenter{
    private static final String TAG = "MainPersenter";
    private MainContract.View mView;

    public MainPersenter(MainContract.View mView) {
        this.mView = mView;
    }

    @Override
    public void start() {

    }

    @Override
    public void release() {

    }

    @Override
    public void getCurrentIp() {
        String mBaseUrl = "";
        String url = WifiUtils.getWifiIp(AppEnv.instance().getContext());
        if(TextUtils.isEmpty(url)){
            ToastUtils.show("请检查网络");
        }
        Log.d(TAG, url + "++++++");
        if (!TextUtils.isEmpty(url)) {
            if (url.contains(".")) {
                String[] ips = url.split("\\.");
                Log.d(TAG, ips.length + "----");
                String last = ips[ips.length - 1];
                mBaseUrl = ApiConstant.URL_HEAD + url.substring(0, (url.length() - last.length()));
            }
        }
        IDLog.d(TAG, "getCurrentIp: " + mBaseUrl);
        //return mBaseUrl;
        mView.setBaseUrl(mBaseUrl);
    }
}
